package cn.lanqiao.facelogin.faceData;

import sun.misc.BASE64Decoder;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Base64Convert {
    public static boolean base64(String base64) throws IOException {
        String substring = base64.substring(22);
        String base64String = substring.replace(" ", "+");
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] bytes1 = decoder.decodeBuffer(base64String);
        String imageUrl ="test.png";
        String path = "F://";
        for (int i = 0; i < bytes1.length; i++) {
            if (bytes1[i] < 0) {
                bytes1[i] += 256;
            }
        }
        File file = new File(path, imageUrl);
        if (!file.exists()) {
            file.createNewFile();
        }
        FileOutputStream out = new FileOutputStream(file);
        out.write(bytes1);
        out.flush();
        out.close();
        return true;
    }
}
